package com.ete.service.util.log

import android.util.Log
import com.blankj.utilcode.util.TimeUtils
import java.text.SimpleDateFormat

/**
 * Author:LiXian
 * <p>
 * Desc:TODO
 * Version:1.0
 * date 2025/4/24 16:31
 */
object EteLog {

    private const val TAG = "EteLog"
    private const val DATE_FORMAT_PATTERN_YMDHMSS = "yyyy-MM-dd HH:mm:ss.SSS"
    private val format: SimpleDateFormat = TimeUtils.getSafeDateFormat(DATE_FORMAT_PATTERN_YMDHMSS)

    @JvmStatic
    fun d(log: String?) {
        d(TAG, log, false)
    }

    @JvmStatic
    fun i(log: String?) {
        i(TAG, log, false)
    }

    @JvmStatic
    fun w(log: String?) {
        w(TAG, log, false)
    }

    @JvmStatic
    fun e(log: String?) {
        e(TAG, log, false)
    }

    @JvmStatic
    fun d(tag: String? = TAG, log: String?, isAddTime: Boolean = false) {
        val newLog = if (isAddTime) {
            "${getTimeStr()},${log}"
        } else {
            log ?: ""
        }
        Log.d(tag ?: TAG, newLog)
    }

    @JvmStatic
    fun i(tag: String? = TAG, log: String?, isAddTime: Boolean = false) {
        val newLog = if (isAddTime) {
            "${getTimeStr()},${log}"
        } else {
            log ?: ""
        }
        Log.i(tag ?: TAG, newLog)
    }

    @JvmStatic
    fun w(tag: String? = TAG, log: String?, isAddTime: Boolean = false) {
        val newLog = if (isAddTime) {
            "${getTimeStr()},${log}"
        } else {
            log ?: ""
        }
        Log.w(tag ?: TAG, newLog)
    }

    @JvmStatic
    fun e(tag: String? = TAG, log: String?, isAddTime: Boolean = false) {
        val newLog = if (isAddTime) {
            "${getTimeStr()},${log}"
        } else {
            log ?: ""
        }
        Log.e(tag ?: TAG, newLog)
    }

    @JvmStatic
    private fun getTimeStr(): String {
        return TimeUtils.getNowString(format)
    }
}